'user strict'
const user = {
  state: {
    user: {
      account: '',
      name: '',
      userId: null,
      img: '',
      video_url: '',
      info_id: ''
    },
    isLogin: 0
  },
  // vuex给外界提供的getter函数
  getters: {
    user (state) {
      return state.user
    },
    isLogin (state) {
      return state.isLogin == 1
    }
  },
  // 同步请求
  mutations: {
    // 修改登录状态
    changeLoginState (state, flag) {
      state.isLogin = flag
    },
    // 存储用户信息
    saveLoginInfo (state, user) {
      state.user.account = user.account
      state.user.name = user.user_name
      state.user.userId = user.user_id
      state.user.img = user.img_url
      state.user.video_url = user.video_url
      state.user.info_id = user.info_id
    }
  },
  // 异步请求
  actions: {
    changeLoginState ({commit}) {
      commit('changeLoginState', 1)
    },
    saveLoginInfo ({commit}) {
      commit('saveLoginInfo', user)
      console.log(user)
    }
  }
}
export default user
